"""
Lifecycle Management Interface for Continual Learning

This interface defines the standard lifecycle hooks for task-based continual learning,
providing clear separation of concerns for different phases of the learning process.
"""

from abc import ABC, abstractmethod


class LifecycleManager(ABC):
    """Interface for managing the lifecycle of continual learning tasks"""

    @abstractmethod
    def before_task(self) -> None:
        """
        Prepare for a new task before training begins

        This method should handle:
        - Task configuration setup
        - Model architecture updates for new classes
        - Data preparation for the current task
        """
        pass

    @abstractmethod
    def before_train(self) -> None:
        """
        Setup before training the current task

        This method should handle:
        - Training configuration initialization
        - Data loader preparation
        - Optimizer and scheduler setup
        - Training metrics initialization
        """
        pass

    @abstractmethod
    def after_train(self) -> None:
        """
        Cleanup and processing after training the current task

        This method should handle:
        - Model state management
        - Best model selection and storage
        - Training statistics logging
        - Memory management updates
        """
        pass

    @abstractmethod
    def after_task(self) -> None:
        """
        Finalize the current task and prepare for the next

        This method should handle:
        - Task evaluation and metrics computation
        - Knowledge consolidation
        - Memory buffer updates
        - Model checkpointing
        """
        pass

    @abstractmethod
    def incremental_train(self) -> None:
        """
        Execute the complete incremental training pipeline for current task

        Returns:
            Dict containing training results and metrics
        """
        pass


class TaskStateManager(ABC):
    """Interface for managing task-specific state information"""

    @abstractmethod
    def get_current_task_id(self) -> int:
        """Get the current task identifier"""
        pass

    @abstractmethod
    def get_known_classes(self) -> int:
        """Get the number of classes seen so far"""
        pass

    @abstractmethod
    def get_total_classes(self) -> int:
        """Get the total number of classes after current task"""
        pass

    @abstractmethod
    def get_task_size(self, task_id: int) -> int:
        """Get the number of classes in a specific task"""
        pass

    @abstractmethod
    def get_task_range(self, task_id: int) -> tuple[int, int]:
        """Get the class range [start, end) for a specific task"""
        pass


class ConfigurationManager(ABC):
    """Interface for managing learner configuration"""

    @abstractmethod
    def get_learning_rate(self, task_id: int) -> float:
        """Get learning rate for specific task"""
        pass

    @abstractmethod
    def get_batch_size(self) -> int:
        """Get batch size for training"""
        pass

    @abstractmethod
    def get_epochs(self, task_id: int) -> int:
        """Get number of epochs for specific task"""
        pass

    @abstractmethod
    def get_device(self) -> str:
        """Get device for computation"""
        pass
